home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earcd / utils / ezcron / ezcron < prev    next >
Text File  |  1998-01-27  |  32KB  |  1,144 lines

  1. /* $VER: EZCron Release 3 by Jim Hines. ©1995-98 (v3.046)
  2. ** EZCron is The Graphic User Interface for EZCrond, ©1994-1998 Jim Hines.
  3. ** Thanks must go to Gene Heskett for his help in coding some functions.
  4. ** Internet email me at <hines_j@iolinc.net>
  5. */
  6.  
  7.     VER            = 'EZCron Release 3 by Jim Hines (v3.046)'
  8.     LF            = '0a'x
  9.     class        = 0
  10.     changes        = 0
  11.  
  12. /*  Main Prefs Vars are:
  13.     versionstr    = prefs.1
  14.     clock        = prefs.2
  15.     convar        = prefs.3
  16.     configfile    = prefs.4
  17.     defevent    = prefs.5
  18.     sfxvar        = prefs.6
  19.     txtedit        = prefs.7
  20. */
  21.  
  22.     datepre.0    = 13
  23.     datepre.1    = 'Once'
  24.     datepre.2    = 'Daily'
  25.     datepre.3    = 'Monthly'
  26.     datepre.4    = 'Sunday'
  27.     datepre.5    = 'Monday'
  28.     datepre.6    = 'Tuesday'
  29.     datepre.7    = 'Wednesday'
  30.     datepre.8    = 'Thursday'
  31.     datepre.9    = 'Friday'
  32.     datepre.10    = 'Saturday'
  33.     datepre.11    = 'Weekdays'
  34.     datepre.12    = 'Weekends'
  35.     datepre.13    = 'EveryNNDD'
  36.     datefunc.0    = 13
  37.     datefunc.1    = date(USA)
  38.     datefunc.2    = '##/##/##'
  39.     datefunc.3    = '##/'right(date(S),2)'/##'
  40.     datefunc.4    = 'sun'
  41.     datefunc.5    = 'mon'
  42.     datefunc.6    = 'tue'
  43.     datefunc.7    = 'wed'
  44.     datefunc.8    = 'thu'
  45.     datefunc.9    = 'fri'
  46.     datefunc.10    = 'sat'
  47.     datefunc.11    = 'Mon|Tue|Wed|Thu|Fri'
  48.     datefunc.12    = 'Sat|Sun'
  49.     datefunc.13    = 'Every_3_Fri'
  50.  
  51.     timepre.0    = 9
  52.     timepre.1    = 'Once'
  53.     timepre.2    = '1 Minute'
  54.     timepre.3    = '5 Minutes' 
  55.     timepre.4    = '10 Minutes'
  56.     timepre.5    = '15 Minutes'
  57.     timepre.6    = '20 Minutes'
  58.     timepre.7    = '30 Minutes'
  59.     timepre.8    = 'Hourly'
  60.     timepre.9    = 'startup'
  61.     timefunc.0    = 9
  62.     timefunc.1    = left(time('N'),5)
  63.     timefunc.2    = '##:##'
  64.     timefunc.3    = '##:#0|##:#5'
  65.     timefunc.4    = '##:#0'
  66.     timefunc.5    = '##:00|##:15|##:30|##:45'
  67.     timefunc.6    = '##:00|##:20|##:40'
  68.     timefunc.7    = '##:00|##:30'
  69.     timefunc.8    = '##:00'
  70.     timefunc.9    = 'startup'
  71.  
  72.     SIGNAL ON ERROR
  73.     SIGNAL ON IOERR
  74.     SIGNAL ON SYNTAX
  75.     SIGNAL ON HALT
  76.     SIGNAL ON BREAK_C
  77.     OPTIONS FAILAT 20
  78.     OPTIONS RESULTS
  79.  
  80.     if ~show('L','rexxsupport.library') then
  81.            call addlib('rexxsupport.library', 0, -30)
  82.     
  83.     if ~show('L','rexxreqtools.library') then
  84.            call addlib("rexxreqtools.library", 0, -30, 0)
  85.  
  86.     if ~showlist('P','VAREXX') then do
  87.            address command 'run >nil: varexx'
  88.         call delay(25)
  89.     end
  90.  
  91.     address VAREXX
  92.     call openport('EZCRONPREFS')
  93.     address command 'waitforport EZCRONPREFS'
  94.     load 'EZCron:ezc.gui EZCRONPREFS'
  95.     host = result
  96.     address value host
  97.     show editwindow
  98.  
  99. startup:
  100.     if showlist('P','EZCROND') then do
  101.         settext text '"Active"'
  102.     end
  103.     if ~showlist('P', 'EZCROND') then do
  104.         settext text '"Inactive"'
  105.     end
  106.     call ReadPrefsFiles()
  107.     call ReadDatePresets()
  108.     call ReadTimePresets()
  109.     if exists('ENV:EZCStartTime') then do
  110.         call open('startdata', 'ENV:EZCStartTime','R')
  111.         startvar = readln('startdata')
  112.         ezcdver = readln('startdata')
  113.         call close('startdata')
  114.         parse var startvar ezcstartdate ezcstarttime
  115.         startuptime = ezcstartdate' at 'ezcstarttime
  116.         settext timeonline startuptime
  117.     end
  118.  
  119.     if exists('s:cron.config') then do /* make sure it's not empty */
  120.         call open('cronfile','s:cron.config','R')
  121.         if readln('cronfile') = ';EZCron Config File' then do /* This just ignores the file header */
  122.             if readln('cronfile') = '' then do
  123.                 call close('cronfile')
  124.                 address command 'delete s:cron.config'
  125.                 call ac_new()
  126.             end
  127.         end
  128.         call close('cronfile')
  129.     end
  130.     else call makeconf()
  131.  
  132.     address command 'copy s:cron.config' prefs.4
  133.  
  134. eventparse:
  135.     address value host  /* this is so the correct window's buttons work after closing other windows */
  136.     drop result ev et rng1 rng2 ed sd edt arg1 sfx txt
  137.  
  138.     do forever
  139.         setlist selectevent clear
  140.         event. = 0
  141.         
  142.         if ~open('cronfile', 's:cron.config', 'R') then do
  143.             call message('Config file not found. Creating a new one.')
  144.             call AC_New()
  145.         end
  146.         
  147.         errors = 0
  148.         do until eof('cronfile')
  149.             linein = readln('cronfile')
  150.             parse var linein line ';'
  151.             next = event.0 + 1
  152.     
  153.             parse var line event.next.command','event.next.pargs','event.next.time',',
  154.             event.next.date','event.next.startdate','event.next.enddate',',
  155.             event.next.rng1','event.next.rng2','event.next.sfx','event.next.txt',',
  156.             event.next.run','event.next.desc','
  157.  
  158.             if event.next.run = '' then event.next.run = N
  159.             if event.next.run = 'N' then event.next.run = '0'
  160.             if event.next.run = 'Y' then event.next.run = '1'
  161.             if event.next.run = 'X' then event.next.run = '2'
  162.  
  163.             event.next.date = translate(event.next.date, 'abcdefghijklmnopqrstuvwxyz',,
  164.                             'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
  165.                             /* THE ABOVE TRANSLATES THE DATE TO LOWERCASE IF NOT NUMERIC */
  166.  
  167.             event.next.time = translate(event.next.time, 'abcdefghijklmnopqrstuvwxyz',,
  168.                             'ABCDEFGHIJKLMNOPQRSTUVWXYZ')
  169.                             /* THE ABOVE TRANSLATES THE TIME TO LOWERCASE IF NOT NUMERIC */
  170.  
  171.             event.next.txt = strip(event.next.txt) /* This Gets rid of the leading & trailing spaces in the LAST variable
  172.                                                       If new fields are added, the variable must be changed to reflect this */
  173.     
  174.             if line ~= '' then do  /* This keeps the commented out lines from appearing */
  175.                 if event.next.desc = '' then event.next.desc = 'No Description Available' /* Check and fix for old config files */
  176.                 setlist selectevent '"'event.next.desc'"'
  177.             end
  178.         
  179.             select
  180.                 when event.next.command = '' then iterate
  181.                 when event.next.command = '' then do
  182.                     iterate
  183.                 end
  184.                 otherwise event.0 = next
  185.             end
  186.         end
  187.         settext eventcount event.0  /* for event counter */
  188.         call close('cronfile')
  189.         call waitforpkt()
  190.     end
  191.  
  192. /* ===== END OF PARSE  */
  193.  
  194. waitforpkt:
  195.     if ((class = delete_event) | (class = loadconfig)  | (class = 'CLOSEWINDOW PrefsWindow')) then NOP
  196.     else do
  197.         if (class = loadevent) then en = event.0
  198.         if (class ~= 0) then do
  199.             setlist selectevent select '"'event.en.desc'"'        /* Reselect the previously selected event */
  200.             call selectevent()
  201.         end
  202.     end
  203.     do forever
  204.         call waitpkt('EZCRONPREFS')    /* Wait for a message from Varexx */
  205.         packet = getpkt('EZCRONPREFS')        /* Get the message */
  206.  
  207.            if packet ~= '00000000'x then do /* This is not a null message */
  208.             call reply(packet, 0)  /* FOR AREXX MESSAGES */
  209.             class  = getarg(packet)    /* Get the information about the message */
  210.             type = word(class, 1)
  211.             msg = word(class, 2)
  212. /*
  213. say 'class =' class
  214. say 'type =' type
  215. say 'msg =' msg
  216. */
  217.             if class = helpgad then call help()
  218.             if class = eventtype then call eventtype()
  219.             if class = quit then call exiting()
  220.             if class = prefsgad then call prefsgad()
  221.             if class = testevent then call testevent()
  222.             if class = AC_New then call AC_New()
  223.             if class = arg1gad then call arggad()
  224.             if class = sfxgad then call sfxgad()
  225.             if class = datefields then call mydate()
  226.             if class = timefields then call mytime()
  227.             if class = indis then call indis()
  228.             if class = update then call update()
  229.             if class = addevent then call copyevent()
  230.             if class = addefault then call addefault()
  231.             if class = delete_event then call deleteevent()
  232.             if class = ac_toggle then call ac_toggle()
  233.             if class = clockon then call clockon()
  234.             if class = refresh then call refresh()
  235.             if class = about then call about()
  236.             if class = loadconfig then call loadconfig()
  237.             if class = saveconfig then call saveconfig()
  238.             if class = loadevent then call loadevent()
  239.             if class = saveevent then call saveevent()
  240.             if class = rexxgad then call rexxgad()
  241.             if class = desced then call description()
  242.             if class = eparse then call eventparse()        /* Arexx only command */
  243.             if msg ~= '' & type = 'SELECTEVENT' then call selectevent()
  244.  
  245.             if class = closewindow then do
  246.                 if (changes = 1) & ~(showlist('P', 'EZCROND')) then do
  247.                     call rtezrequest('EZCronD is not running.'||LF||'Do you want to run it?', 'Yes|No', , 'rt_reqpos = reqpos_centerscr')
  248.                     if rtresult == 1 then address command 'run >nil: rx EZCron:EZCronD'
  249.                 end
  250.                 call exiting()
  251.             end
  252.  
  253.             if type = txtstr then call update()
  254.             if type = rungad then call runreq()
  255.             if type = event & msg ~= '' then call update()
  256.             if type = arg1 & msg ~= '' then call update()
  257.             if type = event_date & msg ~= '' then call update()
  258.             if type = startdate & msg ~= '' then call update()
  259.             if type = enddate & msg ~= '' then call update()
  260.             if type = event_time & msg ~= '' then call update()
  261.             if type = rng1 & msg ~= '' then call update()
  262.             if type = rng2 & msg ~= '' then call update()
  263.             if type = sfx & msg ~= '' then call update()
  264.         end
  265.     end
  266.     return
  267.  
  268. /* CLASSES ROUTINES */
  269.  
  270. help:
  271.     address command 'run >NIL: multiview EZCron:Doc/EZCron.guide'
  272.     return
  273.  
  274. description:
  275.     des = rtgetstring(event.en.desc, 'Edit Event Description', 'Event Description Editor', 'Okay|Cancel',)
  276.     if rtresult == 1 then do
  277.         call update()
  278.     end
  279.     if rtresult == 0 then call waitforpkt()
  280.     return
  281.  
  282. runreq:
  283.     read rungad
  284.     testme = result
  285.     if msg = 0 then event.i.run = 'N'
  286.     if msg = 1 then event.i.run = 'Y'
  287.     if msg = 2 then event.i.run = 'X'
  288.     call update()
  289.     return
  290.  
  291. rexxgad:
  292.     argname = rtfilerequest('EZCron:rexx', , 'Pick an ARexx script to run.',OK, 'rt_reqpos = reqpos_centerscr')
  293.     if argname ~= '' then address command 'run >NIL: rx' argname
  294.     return
  295.  
  296. loadconfig:
  297.     argname = rtfilerequest('EZCron:ConfigFiles', , 'Pick a config file to load', 'OK', 'rt_reqpos = reqpos_centerscr')
  298.     if argname ~= '' then do
  299.         if pos('cron.config', argname) ~= 0 then do
  300.             call rtezrequest(argname 'not a valid file.'||LF||'Please select another.', 'Okay', , 'rt_reqpos = reqpos_centerscr')
  301.             drop argname
  302.             call loadconfig()
  303.         end
  304.         call open('openfile', argname, 'R')
  305.         configtest = readln('openfile')
  306.         call close('openfile')
  307.         if configtest ~= ';EZCron Config File' then do
  308.             call rtezrequest('Not a valid cron.config file', 'OKay')
  309.             return
  310.         end
  311.         address command 'copy' argname 's:cron.config'
  312.         address command 'copy s:cron.config' prefs.4
  313.         drop argname
  314.         call refresh()
  315.     end
  316.     else call waitforpkt()
  317.     return
  318.  
  319. saveconfig:
  320.     argname = rtfilerequest('EZCron:ConfigFiles', , 'Enter a filename to save', OK, 'rt_reqpos = reqpos_centerscr')
  321.     if argname ~= '' then do
  322.         if exists(argname) then do
  323.             call rtezrequest('The file'||LF||argname||LF||'already exists.'||LF||'Do you wish to overwrite it?', 'Yes|Cancel', , 'rt_reqpos = reqpos_centerscr')
  324.             if rtresult == 1 then address command 'copy s:cron.config' '"'argname'"'
  325.             if rtresult == 0 then call waitforpkt()
  326.         end    
  327.         else do
  328.             address command 'copy s:cron.config' '"'argname'"'
  329.         end
  330.     end
  331.     return
  332.  
  333. loadevent:
  334.     argname = rtfilerequest('EZCron:ConfigFiles/Events', , 'Pick an event file to load', 'OK', 'rt_reqpos = reqpos_centerscr')
  335.     if argname ~= '' then do
  336.         call open('openfile', argname, 'R')
  337.         eventline = readln('openfile')
  338.         call close('openfile')
  339.         call open('config', 's:cron.config', A)
  340.         call writeln('config', eventline)
  341.         call close('config')
  342.         address command 'copy s:cron.config' prefs.4
  343.         drop argname
  344.         call refresh()
  345.     end
  346.     else call waitforpkt()
  347.     return
  348.  
  349. saveevent:
  350.     read selectevent NUMBER
  351.     en = RESULT  /* en is the event number */
  352.     if datatype(en, 'N') then do
  353.         argname = rtfilerequest('EZCron:ConfigFiles/Events', , 'Save current event', 'OK', 'rt_reqpos = reqpos_centerscr')
  354.         if argname ~= '' then do
  355.             call open('sevent', argname, 'W')
  356.             call writeln('sevent', event.en.command','event.en.pargs','event.en.time','event.en.date','event.en.startdate','event.en.enddate','event.en.rng1','event.en.rng2','event.en.sfx','event.en.txt','event.en.run','event.en.desc',')
  357.             call close('sevent')
  358.         end
  359.     end
  360.     else do
  361.         call rtezrequest('No file selected.'||LF||'Please select one first.', 'Okay', , 'rt_reqpos = reqpos_centerscr')
  362.     end
  363.     return
  364.  
  365. about:
  366.     call rtezrequest(VER||LF||EZCDVER||LF||'EZCron is emailware.'||LF||'If you use it, please lemme know.',,
  367.     'Well Alrighty Then','About EZCron','rtez_flags=ezreqf_centertext rt_reqpos = reqpos_centerscr',)
  368.     return
  369.  
  370. eventtype:
  371.     call rtezrequest('Please choose what type'||LF||'of  Event you would like.', 'Program|Cancel|Reminder', ,'rt_reqpos = reqpos_centerscr')
  372.     if rtresult == 1 then call getfile()
  373.     if rtresult == 2 then call waitforpkt()
  374.     if rtresult == 0 then call txtgad()
  375.     return
  376.  
  377. clockon:
  378.     if prefs.2 = 'DIGITAL' then clockvar = 'digital format 2'
  379.     if prefs.2 = 'ANALOG' then clockvar = 'seconds'
  380.     address command 'run >nil: clock' clockvar
  381.     return
  382.  
  383. AC_Toggle:
  384.     if ~showlist('P', 'EZCROND') then do
  385.         address command 'run >nil: rx EZCron:EZCronD'
  386.     end    
  387.     else
  388.     if showlist('P', 'EZCROND') then do    
  389.         address command 'run >nil: rx EZCron:EZCronD'
  390.         settext text '"Wait..Exiting"'
  391.         set ac_toggle disable
  392.     end
  393.     return
  394.  
  395. testevent:
  396.     read event
  397.     ev = RESULT
  398.     if left(ev,1) = '!' then ev = substr(ev,2,256)
  399.     
  400.     read arg1
  401.     arg1 = RESULT
  402.     if arg1 = '-' then arg1 = ''
  403.     
  404.     read sfx
  405.     fx = RESULT
  406.     if fx = '-' then fx = ''
  407.     
  408.     read txtstr
  409.     tx = result
  410.                 
  411.     if ev ~= textreminder then do
  412.         address command 'run' prefs.3 ev arg1
  413.     end
  414.     
  415.     if fx ~= '' then do
  416.         address command 'run >nil:' prefs.6 fx
  417.     end
  418.     
  419.     if ev = TEXTREMINDER then do
  420.         address command 'run >nil: rx >nil: ezcron:rexx/Reminder.rexx' tx
  421.         if showlist(h,SPEAK) then do
  422.             address command 'echo' '"'tx'"' '>speak:'
  423.         end
  424.     end
  425.     drop result ev et ed arg1 rng1 rng2 sfx txt
  426.     return
  427.  
  428. selectevent:
  429.     read selectevent NUMBER
  430.     en = RESULT  /* en is the event number */
  431.     read selectevent
  432.     des = result
  433.  
  434.     msg = event.en.command
  435.     settext event msg
  436.     set arg1 arg1gad rungad enable
  437.     if msg = 'TEXTREMINDER' | msg = '!TEXTREMINDER' then do
  438.         set arg1 arg1gad rungad disable
  439.         set txtstr enable        /****/
  440.     end
  441.     settext event_time event.en.time
  442.     settext event_date event.en.date
  443.     settext rng1 event.en.rng1
  444.     settext rng2 event.en.rng2
  445.     settext startdate event.en.startdate
  446.     settext enddate event.en.enddate
  447.     settext arg1 event.en.pargs
  448.     settext rng1 event.en.rng1
  449.     settext rng2 event.en.rng2
  450.     settext sfx event.en.sfx
  451.     settext txtstr event.en.txt
  452.     if event.en.txt = '-' then do
  453.         set txtstr disable            /****/
  454.     end
  455.     setnum rungad event.en.run
  456.     return
  457.  
  458. getfile:
  459.     set arg1 arg1gad enable
  460.     clock = time('N')
  461.     clock2 = LEFT(clock,5)
  462.     filename = rtfilerequest('EZCron:', , "Pick a File To Run",OK,'rt_reqpos = reqpos_centerscr')
  463.     if filename = '' then call eventparse() /* Get out of routine */
  464.  
  465.     des = rtgetstring(,'Enter Event Description', 'Event Description Requester', 'Okay|Cancel','rt_reqpos = reqpos_centerscr')
  466.     if rtresult == 1 then event.en.desc = des
  467.     if rtresult == 0 then call waitforpkt()
  468.     
  469.     settext event filename
  470.     settext event_time clock2
  471.     settext rng1 '--:--'
  472.     settext rng2 '--:--'
  473.     settext event_date Date(USA)
  474.     settext startdate '--/--/--'
  475.     settext enddate '--/--/--'
  476.     settext arg1 '-'
  477.     settext sfx '-'
  478.     settext txtstr '-'
  479.     set txtstr disable /****/
  480.     setnum rungad '0'
  481.     call addevent()
  482.     return
  483.  
  484. AC_New:
  485.     if ~exists('s:cron.config') then call makeconf()
  486.     else call rtezrequest('A cron.config file already exists.'||LF||'Do you wish to overwrite it?.', '_Yes|_No', , 'rt_reqpos = reqpos_centerscr')
  487.     if rtresult == 1 then do
  488.         address command 'delete >NIL: s:cron.config'
  489.         call makeconf()
  490.     end
  491.     address command 'copy s:cron.config' prefs.4
  492.     call refresh()
  493.     return
  494.     
  495. arggad:
  496.     argname = rtfilerequest('EZCron:', , 'Pick a file argument',OK)
  497.     if rtresult == 1 then do
  498.         if argname = '' then argname = '-'
  499.         settext arg1 argname
  500.         call update()
  501.     end
  502.     return
  503.  
  504. sfxgad:
  505.     read sfx
  506.     sfxtxt = result
  507.     parse var sfxtxt device ':'
  508.     if device = '-' then device = 'sys'
  509.     argname = rtfilerequest(device':',, 'Pick a soundfile',OK,)
  510.     if rtresult == 1 then do
  511.         if argname = '' then argname = '-'
  512.         settext sfx argname
  513.         call update()
  514.     end
  515.     return    
  516.  
  517. txtgad:
  518.     read txtstr
  519.     txt = result
  520.     if txt = '-' then txt = ''
  521.     argname = rtgetstring(txt,'Enter Reminder String', 'Reminder Requester', , 'rt_reqpos = reqpos_centerscr')
  522.     if argname = '' then call eventparse()
  523.  
  524.     des = rtgetstring('+++REMINDER+++ ', 'Enter Event Description', 'Event Description Requester', 'Okay|Cancel','rt_reqpos = reqpos_centerscr')
  525.     if rtresult == 1 then event.en.desc = des
  526.     if rtresult == 0 then call waitforpkt()
  527.  
  528.     clock = time('N')
  529.     clock2 = LEFT(clock,5)
  530.     settext txtstr argname
  531.     settext event TextReminder
  532.     settext event_time clock2
  533.     settext event_date Date(USA)
  534.     settext startdate '--/--/--'
  535.     settext enddate '--/--/--'
  536.     set arg1 disable
  537.     settext arg1 '-'
  538.     settext sfx '-'
  539.     setnum rungad '0'
  540.     drop txt
  541.     call addevent()
  542.     return
  543.  
  544. prefsgad:
  545.     call openport('PREFSWINPORT')
  546.     spawn PREFSWINPORT
  547.     host2 = result
  548.     address value host2
  549.     show prefswindow
  550.     call prefs()
  551.     return
  552.  
  553. mydate:
  554.     call openport('DATEWINPORT')
  555.     spawn DATEWINPORT
  556.     host3 = result
  557.     address value host3
  558.     show datewindow
  559.     call datefields()
  560.     return
  561.  
  562. mytime:
  563.     call openport('TIMEWINPORT')
  564.     spawn TIMEWINPORT
  565.     host4 = result
  566.     address value host4
  567.     show timewindow
  568.     call timefields()
  569.     return
  570.  
  571. indis: /* Enable/Disable event */
  572.     read event
  573.     ev = result
  574.     read selectevent NUMBER
  575.     n = result
  576.     des = event.n.desc
  577.  
  578.     if left(ev, 1) = '!' then do
  579.         ev = substr(ev,2,256) /* start with 2nd char and go 256 deep */
  580.         settext event ev
  581.         des = delstr(des, 1, 1)
  582.         des = delstr(des, length(des), 1)
  583.         call update()
  584.     end
  585.     else do
  586.         settext event '!'ev
  587.         des = '('des')'
  588.         call update()
  589.     end
  590.     return
  591.  
  592. update: /* Modify */
  593.     changes = 1
  594.     read event
  595.     ev = result
  596.     if ev = '' then call message('No Event Field.')
  597.     if ev = '' then call eventparse()
  598.     if ev = 'None Selected' then call message('No Event Field.')
  599.     if ev = 'None Selected' then call eventparse()
  600.     read event_time
  601.     et = result
  602.     if et = '' then    call message('No Time Field.')
  603.     read event_date
  604.     ed = result
  605.     if ed = '' then call message('No Date Field.')
  606.     if et = 'startup' then do
  607.         settext event_date 'startup'
  608.         ed = 'startup'
  609.     end
  610.     read startdate
  611.     sd = result
  612.     if sd = '' then sd = '--/--/--'
  613.     read enddate
  614.     edt = result
  615.     if edt = '' then edt = '--/--/--'
  616.     read arg1
  617.     arg = result
  618.     if arg = '' then arg = '-'
  619.     read rng1
  620.     trng1 = result
  621.     if trng1 = '' then trng1 = '--:--'
  622.     read rng2
  623.     trng2 = result
  624.     if trng2 = '' then trng2 = '--:--'
  625.     read sfx
  626.     fx = result
  627.     if fx = '' then fx = '-'
  628.     read txtstr
  629.     rem = result
  630.     if rem = '' then rem = '-'
  631.     read rungad
  632.     runit = result
  633.     if runit = '' then runit = '0'
  634.  
  635.     if des ~= '' then event.en.desc = des
  636.     else des = event.en.desc
  637.  
  638.     address command 'delete >NIL: s:cron.config'
  639.     call open('dfile', 's:cron.config', 'W') /* create it again*/
  640.     call close('dfile')
  641.  
  642.     read selectevent var h
  643.     call open('dfile', 's:cron.config', 'a')
  644.     call writeln('dfile', ';EZCron Config File')
  645.     do i = 1 to h.count
  646.         if en ~= i then do
  647.             call writeln('dfile', event.i.command','event.i.pargs','event.i.time','event.i.date','event.i.startdate','event.i.enddate','event.i.rng1','event.i.rng2','event.i.sfx','event.i.txt','event.i.run','event.i.desc',')
  648.             drop result
  649.         end
  650.         else do
  651.             call writeln('dfile', ev','arg','et','ed','sd','edt','trng1','trng2','fx','rem','runit','des',')
  652.         end
  653.     end
  654.     call close('dfile')
  655.     drop result ev et ed sd edt arg1 rng1 rng2 sfx txt runit
  656.     address command 'copy s:cron.config' prefs.4
  657.     call eventparse()
  658.  
  659. copyevent:
  660.     copy = 1
  661. addevent:    /* Copy Event */
  662.     read event
  663.     ev = result
  664.     if ev = '' then call eventtype()
  665.     if ev = 'None Selected' then call eventtype()
  666.                 
  667.     read event_time
  668.     et = result
  669.     if et = '' then    call message('No Time Field.')
  670.     
  671.     read event_date
  672.     ed = result
  673.     if ed = '' then call message('No Date Field.')
  674.  
  675.     read startdate
  676.     sd = result
  677.     if sd = '' then sd = '--/--/--'
  678.  
  679.     read enddate
  680.     edt = result
  681.     if edt = '' then edt = '--/--/--'
  682.         
  683.     read arg1
  684.     arg1 = result
  685.     if arg1 = '' then arg1 = '-'
  686.  
  687.     read rng1
  688.     rng1 = result
  689.     if rng1 = '' then rng1 = '--:--'
  690.  
  691.     read rng2
  692.     rng2 = result
  693.     if rng2 = '' then rng2 = '--:--'
  694.     
  695.     read sfx
  696.     sfx = result
  697.     if sfx = '' then sfx = '-'
  698.     
  699.     read txtstr
  700.     txt = result
  701.     if txt = '' then txt = '-'
  702.  
  703.     read rungad
  704.     runit = result
  705.     if runit = '' then runit = 'N'
  706.                 
  707.     if ev = '' then call eventparse()
  708.     if ev = 'None Selected' then call eventparse()
  709.     if et = '' then call eventparse()
  710.     if ed = '' then call eventparse()
  711.  
  712.     if et = 'startup' then do
  713.         settext event_date 'startup'
  714.         ed = 'startup'
  715.     end
  716.  
  717.     if copy = 1 then do
  718.         if pos('(', event.en.desc) ~= 0 then do
  719.             call message('You cannot copy a disabled event.')
  720.             call eventparse()
  721.         end
  722.         event.en.desc = 'Copy of 'event.en.desc
  723.     end
  724.     call open('dfile', 's:cron.config', 'A')
  725.     call writeln('dfile', ev','arg1','et','ed','sd','edt','rng1','rng2','sfx','txt','runit','event.en.desc',')
  726.     call close('dfile')
  727.     drop result ev et ed sd edt arg1 rng1 rng2 sfx txt runit copy
  728.     address command 'copy s:cron.config' prefs.4
  729.     call eventparse()
  730.             
  731. addefault:
  732.     read event
  733.     ev = result
  734.     if ev = '' then call message('No Event Field.')
  735.     if ev = 'None Selected' then call message('No Event Field.')
  736.     if ev = '' then call eventparse()
  737.     if ev = 'None Selected' then call eventparse()
  738.     if et = '' then call eventparse()
  739.     if ed = '' then call eventparse()
  740.  
  741.     prefs.5 = ev','event.en.pargs','event.en.time','event.en.date','event.en.startdate','event.en.enddate','event.en.rng1','event.en.rng2','event.en.sfx','event.en.txt','event.en.run','event.en.desc','
  742.     if exists('EZCron:Prefs/EZCron.prefs') then address command 'delete >NIL: EZCron:prefs/EZCron.prefs'
  743.     call open('cronprefs','EZCron:prefs/EZCron.prefs', 'W')
  744.     do i = 1 to 7
  745.         call writeln('cronprefs', prefs.i)
  746.     end
  747.     call close('cronprefs')
  748.     call eventparse()
  749.     return
  750.  
  751. deleteevent:
  752.     address command 'delete >NIL: s:cron.config'
  753.     call open('dfile', 's:cron.config', 'W') /* create it again*/
  754.     call close('dfile')
  755.  
  756.     read event_time
  757.     et = result
  758.     read selectevent var h
  759.     call open('dfile', 's:cron.config', 'A')
  760.     call writeln('dfile', ';EZCron Config File')
  761.     do n = 1 to h.count
  762.         if en ~= n then do
  763.             call writeln('dfile', event.n.command','event.n.pargs','event.n.time','event.n.date','event.n.startdate','event.n.enddate','event.n.rng1','event.n.rng2','event.n.sfx','event.n.txt','event.n.run','event.n.desc',')
  764.         end
  765.     end
  766.     call close('dfile')
  767.     address command 'copy s:cron.config' prefs.4
  768.     
  769.     settext event 'None Selected'
  770.     settext event_time 'NA'
  771.     settext event_date 'NA'
  772.     settext startdate '--/--/--'
  773.     settext enddate '--/--/--'
  774.     settext arg1 '-'
  775.     settext rng1 '--:--'
  776.     settext rng2 '--:--'
  777.     settext sfx '-'
  778.     settext txtstr '-'
  779.     setnum rungad '0'
  780.     call eventparse()
  781.  
  782. refresh:
  783.     if showlist('P', 'EZCROND') then do
  784.         settext text '"Active"'
  785.     end
  786.     if ~showlist('P', 'EZCROND') then do
  787.         settext text '"Inactive"'
  788.     end
  789.     set ac_toggle enable
  790.     settext event 'None Selected'
  791.     settext event_time 'NA'
  792.     settext event_date 'NA'
  793.     settext startdate '--/--/--'
  794.     settext enddate '--/--/--'
  795.     settext arg1 '-'
  796.     settext rng1 '--:--'
  797.     settext rng2 '--:--'
  798.     settext sfx '-'
  799.     settext txtstr '-'
  800.     setnum rungad '0'
  801.     class = 0
  802.     type = 0
  803.     msg = 0
  804.     call eventparse()
  805.     return
  806.  
  807. prefs:
  808.     do forever
  809.         settext conselectpath prefs.3
  810.         settext sfxplayerpath prefs.6
  811.         settext configprefspath prefs.4
  812.         call waitpkt('PREFSWINPORT')    /* Wait for a message from Varexx */
  813.         packet = getpkt('PREFSWINPORT') /* Get the message */
  814.         if packet ~= '00000000'x then do /* This is not a null message */
  815.             class  = getarg(packet)        /* Get the information about the message */
  816.                type = word(class, 1)
  817.             msg = substr(class, 11,25)
  818.  
  819.             if class = 'CLOSEWINDOW PrefsWindow' then call closewindow()
  820.             if class = useprefs then call closewindow()
  821.             if class = sfxplayer then do
  822.                 sfxplay = rtfilerequest('EZCron:', , 'Pick a sound player',OK, 'rt_reqpos = reqpos_centerscr')
  823.                 if rtresult == 0 then call prefs() /*This get out of the edprefs function */
  824.                 else prefs.6 = sfxplay
  825.                 drop sfxplay
  826.                 call prefs()
  827.             end
  828.             if class = conselect then do
  829.                 console = rtgetstring(prefs.3, 'Enter Output String', 'Test Output Requester', ,)
  830.                 if console ~= '' then prefs.3 = console
  831.                 if rtresult == 0 then call prefs() /*This get out of the edprefs function */
  832.                 drop console
  833.                 call prefs()
  834.             end
  835.             if class = clockprefs then do
  836.                 call rtezrequest('Pick a clock type.', 'Analog|Cancel|Digital', ,)
  837.                 if rtresult == 1 then prefs.2 = analog
  838.                 if rtresult == 2 then call prefs()
  839.                 if rtresult == 0 then prefs.2 = digital
  840.                 call prefs()
  841.             end
  842.             if class = configprefs then do
  843.                 configrt = rtgetstring(prefs.4, 'Enter Path for cron.config', 'cron.config prefs', ,)
  844.                 if configrt ~= '' then do
  845.                     prefs.4 = configrt
  846.                     call rtezrequest('You must restart the daemon!','Okay,!','EZCron ERROR','rt_reqpos = reqpos_centerscr rtez_flags=ezreqf_centertext',)
  847.                 end
  848.                 if rtresult == 0 then call prefs() /*This get out of the edprefs function */
  849.                 drop configrt
  850.                 call prefs()
  851.             end
  852.             if class = saveprefs then do
  853.                 if exists('EZCron:Prefs/EZCron.prefs') then address command 'delete >NIL: EZCron:prefs/EZCron.prefs'
  854.                 call open('cronprefs','EZCron:prefs/EZCron.prefs', 'W')
  855.                 do i = 1 to 7
  856.                     call writeln('cronprefs', prefs.i)
  857.                 end
  858.                 call close('cronprefs')
  859.                 call closewindow()
  860.             end
  861.         call prefs()
  862.         end    
  863.     end
  864.  
  865. datefields:
  866.     setlist datelist clear
  867.     if datatype(datepre.0, 'N') then do
  868.         do i = 1 to datepre.0
  869.             setlist datelist '"'datepre.i'"'
  870.         end
  871.     end
  872.     datepkts:
  873.     do forever
  874.         call waitpkt('DATEWINPORT')        /* Wait for a message from Varexx */
  875.         packet = getpkt('DATEWINPORT')    /* Get the message */
  876.     
  877.         if packet ~= '00000000'x then do    /* This is not a null message */
  878.             class  = getarg(packet)            /* Get the information about the message */
  879.             type   = word(class, 1)
  880.             msg    = substr(class, 10, 255)
  881.             if type = DATELIST then do
  882.                 read datelist NUMBER
  883.                 i = result
  884.                 field = datefunc.i
  885.             end
  886.             if class = 'CLOSEWINDOW DateWindow' then do
  887.                 hide
  888.                 address value host
  889.                 call waitforpkt()
  890.             end
  891.             if type = acceptdatepre then call fillindate()
  892.  
  893.  
  894.             if type = deletedatepre then do
  895.                 if datepre.0 > 13 then do
  896.                     address command    'delete ezcron:prefs/datepre.prefs'
  897.                     call open('newpre','EZCron:prefs/datepre.prefs', 'W')
  898.                     do r = 14 to datepre.0
  899.                         if r ~= i then do
  900.                             call writeln('newpre',datepre.r','datefunc.r)
  901.                         end
  902.                     end
  903.                     call close('newpre')
  904.                 end
  905.                 else do
  906.                     call rtezrequest('You have selected a non-deletable preset.', 'Okay', , 'rt_reqpos = reqpos_centerscr')
  907.                     call datepkts()
  908.                 end
  909.                 datepre.0 = 13 /* Reset before reading the files again */
  910.                 call ReadDatePresets()
  911.                 call datefields()
  912.             end
  913.  
  914.             if type = editdatepre then do
  915.                 if i < 14 then do
  916.                     call rtezrequest('You have selected a non-editable preset.', 'Okay', , 'rt_reqpos = reqpos_centerscr')
  917.                     call datepkts()
  918.                 end
  919.                 editpre = rtgetstring(datepre.i','datefunc.i,'Edit Date Preset'||LF||'Use format (Label,Field)', 'Edit Date Preset', 'Okay|Cancel',)
  920.                 if rtresult == 1 then do
  921.                     parse var editpre datepre.i','datefunc.i
  922.                     call writedatepresets()
  923.                     call datefields()
  924.                 end
  925.                 if rtresult == 0 then call datepkts()
  926.             end
  927.             if type = newdatepre then do
  928.                 newpre = rtgetstring(,'Add New Date Preset'||LF||'Use format (Label,Field)', 'Add Date Preset', 'Okay|Cancel',)
  929.                 if rtresult == 1 then do
  930.                     datepre.0 = datepre.0 + 1
  931.                     n = datepre.0
  932.                     parse var newpre datepre.n','datefunc.n
  933.                     call writedatepresets()
  934.                     drop newpre rtresult n
  935.                     call datefields() /* re write the listview */
  936.                 end
  937.                 if rtresult == 0 then call datepkts()
  938.             end
  939.             call datepkts()
  940.         end
  941.     end
  942.  
  943. timefields:
  944.     setlist timelist clear
  945.     if datatype(timepre.0, 'N') then do
  946.         do i = 1 to timepre.0
  947.             setlist timelist '"'timepre.i'"'
  948.         end
  949.     end
  950.     timepkts:
  951.     do forever
  952.         call waitpkt('TIMEWINPORT')        /* Wait for a message from Varexx */
  953.         packet = getpkt('TIMEWINPORT')    /* Get the message */
  954.     
  955.         if packet ~= '00000000'x then do    /* This is not a null message */
  956.             class  = getarg(packet)            /* Get the information about the message */
  957.             type   = word(class, 1)
  958.             msg    = substr(class, 10, 255)
  959.             if type = TIMELIST then do
  960.                 read timelist NUMBER
  961.                 i = result
  962.                 field = timefunc.i
  963.             end
  964.             if class = 'CLOSEWINDOW TimeWindow' then do
  965.                 hide
  966.                 address value host
  967.                 call waitforpkt()
  968.             end
  969.             if type = accepttimepre then call fillintime()
  970.             if type = deletetimepre then do
  971.                 if timepre.0 > 9 then do
  972.                     address command    'delete ezcron:prefs/timepre.prefs'
  973.                     call open('newpre','EZCron:prefs/timepre.prefs', 'W')
  974.                     do r = 10 to timepre.0
  975.                         if r ~= i then do
  976.                             call writeln('newpre',timepre.r','timefunc.r)
  977.                         end
  978.                     end
  979.                     call close('newpre')
  980.                 end
  981.                 else do
  982.                     call rtezrequest('You have selected a non-deletable preset.', 'Okay', , 'rt_reqpos = reqpos_centerscr')
  983.                     call timepkts()
  984.                 end
  985.                 timepre.0 = 9 /* Reset before reading the files again */
  986.                 call ReadTimePresets()
  987.                 call timefields()
  988.             end
  989.  
  990.             if type = edittimepre then do
  991.                 if i < 10 then do
  992.                     call rtezrequest('You have selected a non-editable preset.', 'Okay', , 'rt_reqpos = reqpos_centerscr')
  993.                     call timepkts()
  994.                 end
  995.                 editpre = rtgetstring(timepre.i','timefunc.i,'Edit Time Preset'||LF||'Use format (Label,Field)', 'Edit Time Preset', 'Okay|Cancel',)
  996.                 if rtresult == 1 then do
  997.                     parse var editpre timepre.i','timefunc.i
  998.                     call writetimepresets()
  999.                     call timefields()
  1000.                 end
  1001.                 if rtresult == 0 then call timepkts()
  1002.             end
  1003.             if type = newtimepre then do
  1004.                 newpre = rtgetstring(,'Add New Time Preset'||LF||'Use format (Label,Field)', 'Add Time Preset', 'Okay|Cancel',)
  1005.                 if rtresult == 1 then do
  1006.                     timepre.0 = timepre.0 + 1
  1007.                     n = timepre.0
  1008.                     parse var newpre timepre.n','timefunc.n
  1009.                     call writetimepresets()
  1010.                     drop newpre rtresult n
  1011.                     call timefields() /* re write the listview */
  1012.                 end
  1013.                 if rtresult == 0 then call timepkts()
  1014.             end
  1015.             call timepkts()
  1016.         end
  1017.     end
  1018.  
  1019. fillindate:
  1020.     hide
  1021.     address value host
  1022.     settext event_date field
  1023.     call update()
  1024.  
  1025. fillintime:
  1026.     hide
  1027.     address value host
  1028.     settext event_time field
  1029.     call update()
  1030.  
  1031. writedatepresets:
  1032.     if exists('EZCron:prefs/datepre.prefs') then address command 'delete EZCron:prefs/datepre.prefs'
  1033.     call open('newpre', 'EZCron:prefs/datepre.prefs', 'W')
  1034.     do i = 14 to datepre.0
  1035.         call writeln('newpre', datepre.i','datefunc.i)
  1036.     end
  1037.     call close('newpre')
  1038.     return
  1039.  
  1040. writetimepresets:
  1041.     if exists('EZCron:prefs/timepre.prefs') then address command 'delete EZCron:prefs/timepre.prefs'
  1042.     call open('newpre', 'EZCron:prefs/timepre.prefs', 'W')
  1043.     do i = 10 to timepre.0
  1044.         call writeln('newpre', timepre.i','timefunc.i)
  1045.     end
  1046.     call close('newpre')
  1047.     return
  1048.  
  1049.  
  1050. ReadPrefsFiles:
  1051.     if exists('EZCron:prefs/EZCron.prefs') then do
  1052.         call open('ezconfig','EZCron:Prefs/EZCron.prefs','R')
  1053.         do i = 1 to 7
  1054.             prefs.i = readln('ezconfig')
  1055.         end
  1056.         call close('ezconfig')
  1057.     end
  1058.     else do
  1059.         prefs.1        = VER
  1060.         prefs.2        = 'ANALOG'
  1061.         prefs.3        = '>CON:100/100/400/100/CronTestEvent/Close'
  1062.         prefs.4        = 't:cron.config'
  1063.         prefs.5        = 'rx,ezcron:rexx/cookooclock.rexx,##:00|##:30,##/##/##,--/--/--,--/--/--,00:01,18:59,-,-,0,Cookoo Clock Script,'
  1064.         prefs.6        = 'c:play16'
  1065.         prefs.7        = 'c:ed'
  1066.     end
  1067.     return
  1068.  
  1069. ReadDatePresets:
  1070.     if exists('EZCron:prefs/datepre.prefs') then do
  1071.         call open('dtconfig','EZCron:Prefs/datepre.prefs','R')
  1072.         do until eof('dtconfig')
  1073.             linein = readln('dtconfig')
  1074.             datepre.0 = datepre.0 + 1
  1075.         end
  1076.         datepre.0 = datepre.0 - 1
  1077.         call seek('dtconfig', 0, 'B')
  1078.         do i = 14 to datepre.0
  1079.             datepre.i = readln('dtconfig')
  1080.             parse var datepre.i datepre.i ',' datefunc.i
  1081.         end
  1082.         call close('dtconfig')
  1083.     end
  1084.     return
  1085.  
  1086. ReadTimePresets:
  1087.     if exists('EZCron:prefs/timepre.prefs') then do
  1088.         call open('tmconfig','EZCron:Prefs/timepre.prefs','R')
  1089.         do until eof('tmconfig')
  1090.             linein = readln('tmconfig')
  1091.             timepre.0 = timepre.0 + 1
  1092.         end
  1093.         timepre.0 = timepre.0 - 1
  1094.         call seek('tmconfig', 0, 'B')
  1095.         do i = 10 to timepre.0
  1096.             timepre.i = readln('tmconfig')
  1097.             parse var timepre.i timepre.i ',' timefunc.i
  1098.         end
  1099.         call close('tmconfig')
  1100.     end
  1101.     return
  1102.  
  1103. helpmessage: procedure
  1104.     call rtezrequest(arg(1),'Okay!','EZCron Online Help','rtez_flags=ezreqf_centertext',)
  1105.     return
  1106.  
  1107. message: procedure
  1108.     call rtezrequest(arg(1),'Okay!','EZCron ERROR','rt_reqpos = reqpos_centerscr rtez_flags=ezreqf_centertext',)
  1109.     return
  1110.  
  1111. makeconf:             /* Create it if cron.config ~exists */
  1112.     if ~exists('s:cron.config') then do
  1113.         call message('Config file not found. Creating a new one.')
  1114.         call open('cronfile','s:cron.config', 'W')
  1115.         call writeln('cronfile', ';EZCron Config File')
  1116.         call writeln('cronfile', prefs.5)
  1117.         call close('cronfile')
  1118.     end
  1119.     return
  1120.  
  1121. closewindow:
  1122.     hide
  1123.     address value host
  1124.     call refresh()
  1125.     return
  1126.  
  1127. syntax:
  1128. ioerr:
  1129. error:
  1130.     errorrc = RC
  1131.     call rtezrequest('EZCron has exited with an error'||LF||'Line' SIGL ERRORTEXT(errorrc),'Okay!','EZCron FATAL ERROR','rt_reqpos = reqpos_centerscr rtez_flags=ezreqf_centertext',)
  1132.     call exiting()
  1133.  
  1134. exiting:
  1135. break_c:
  1136.     hide unload        /* Hide the window and unload the gui */
  1137.     call closeport('EZCRONPREFS')
  1138.     address command 'sys:rexxc/vxc >nil:'
  1139.     address command 'sys:rexxc/vxc >nil:'
  1140.     address command 'sys:rexxc/vxc >nil:'
  1141.     address command 'sys:rexxc/vxc >nil:'
  1142.     address command 'run >nil: avail flush'    
  1143.     exit
  1144.